package com.mvvm.ktnet.daoUtil

import android.database.sqlite.SQLiteDatabase
import com.mvvm.ktnet.application.App
import com.mvvm.ktnet.dao.DaoMaster
import com.mvvm.ktnet.dao.DaoSession
import com.mvvm.ktnet.dao.StudentDao
import com.mvvm.ktnet.dao.TestDaoDao

class GreenDaoStudentUtils {
    companion object {
        private val mInstance by lazy { GreenDaoStudentUtils() }

        @JvmStatic
        fun getInstance(): GreenDaoStudentUtils {
            return mInstance
        }
    }

    private var daoSession: DaoSession
    private var daoMaster: DaoMaster
    private var helper: AppOpenHelper
    private var db: SQLiteDatabase

    fun getBaseDb(): SQLiteDatabase {
        return db
    }

    init {
        helper = AppOpenHelper(App.context, "student.sqlite", null)
        db = helper.writableDatabase
        daoMaster = DaoMaster(db)
        daoSession = daoMaster.newSession()
    }

    fun toInit(){
        db.close()
        helper = AppOpenHelper(App.context, "student.sqlite", null)
        db = helper.writableDatabase
        daoMaster = DaoMaster(db)
        daoSession = daoMaster.newSession()
    }

    private var clear = false

    fun getStudentDao(): StudentDao {
        return  daoSession.studentDao
    }

    fun getDaoSession(): DaoSession {
        return daoSession
    }

}